<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('考场学生安排列表')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">学生考场位置查询</a>
                        </li>
                        <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false" onclick="queryScheduleList()">考试计划查询</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane active">
                            <div class="col-sm-12 search-collapse">
                                <form id="formId">
                                    <div class="select-list">

                                        <ul>
                                            <li>
                                                <label>年级：</label>
                                                <select name="gradeId" th:with="type=${@grade.getGradeList()}">
                                                    <option value="">所有</option>
                                                    <option th:each="grade : ${type}" th:text="${grade.gradeName}" th:value="${grade.id}"></option>
                                                </select>
                                            </li>
                                            <li>
                                                <label>位置：</label><input type="text" name="location"/>
                                            </li>
                                            <li>
                                                <label>学号：</label><input type="text" name="studentNo"/>
                                            </li>
                                            <li>
                                                <label>学生姓名：</label><input type="text" name="studentName"/>
                                            </li>
                                            <li>
                                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                            </li>
                                        </ul>
                                    </div>
                                </form>
                            </div>
                            <div class="col-sm-12 select-table table-striped">
                                <table id="bootstrap-table"></table>
                            </div>
                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="col-sm-12 search-collapse">
                                <form id="formId2" class="form-horizontal">
                                    <div class="row">
                                        <div class="form-group">
                                            <label class="col-sm-1 control-label">考试计划：</label>
                                            <div class="col-sm-4">
                                                <select name="id" th:with="type=${@examSchedule.getScheduleList()}" class='form-control selectpicker' data-live-search="true">
                                                    <option value="">所有</option>
                                                    <option th:each="schedule : ${type}" th:text="${schedule.name}" th:value="${schedule.id}"></option>
                                                </select>
                                            </div>
                                            <label class="col-sm-1 control-label">年级：</label>
                                            <div class="col-sm-4">
                                                <select name="gradeId" th:with="type=${@grade.getGradeList()}" class='form-control selectpicker' data-live-search="true">
                                                    <option value="">所有</option>
                                                    <option th:each="grade : ${type}" th:text="${grade.gradeName}" th:value="${grade.id}"></option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="queryScheduleList()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                </form>
                            </div>
                            <div class="col-sm-12 select-table table-striped">
                                <table id="bootstrap-table2"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-select-js" />
     <script th:src="@{/js/common/date_utils.js}"></script>
    <script th:inline="javascript">
        var semesterDatas = [[${@dict.getType('sc_term_type')}]];
        var prefix = ctx + "school/roomStudents";
        $(function() {
            var options = {
                url: prefix + "/list",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "考场学生安排",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'Id',
                    visible: false
                },
                {
                    field: 'clazzId',
                    title: '考场Id',
                    visible: false
                },
                {
                    field: 'examName',
                    title: '考试名称',
                },
                {
                    field: 'roomId',
                    title: '考场'
                },
                {
                    field: 'location',
                    title: '考场位置'
                },
                {
                    field: 'studentNo',
                    title: '学号'
                },
                {
                    field: 'studentName',
                    title: '学生姓名'
                },

                {
                    field: 'orderGrade', 
                    title: '年级顺序',
                    visible: false
                },
                {
                    field: 'orderClazz', 
                    title: '考场顺序',
                    visible: false
                },
                {
                    field: 'siteNo', 
                    title: '座位号'
                },
                // {
                //     title: '操作',
                //     align: 'center',
                //     formatter: function(value, row, index) {
                //         var actions = [];
                //         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // }
                ]
            };
            $.table.init(options);
        });

        var optionsw = {
            detailView: true,
            striped : true, //是否显示行间隔色
            pagination : true,//是否分页
            sidePagination : 'client',//server:服务器端分页|client：前端分页
            onExpandRow : function(index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [
                {
                checkbox: false
                },
                {
                    field: 'id',
                    title: 'Id',
                    visible: false
                },
                {
                    field: 'examId',
                    title: '场次编号',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'semester',
                    title: '学期',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(semesterDatas, value);
                    }
                },
                {
                    field: 'gradeId',
                    title: '年级Id',
                    visible: false
                },
                {
                    field: 'gradeName',
                    title: '年级名称'
                },
                {
                    field: 'examTime',
                    title: '考试开始日期',
                    formatter:dateFormatterYMD
                },
                {
                    field: 'examEnd',
                    title: '考试结束日期',
                    formatter:dateFormatterYMD
                },
                {
                    field: 'total',
                    title: '总人数'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" onclick="printSchedule('+row.id+')"><i class="fa fa-print"></i>打印</a> ');
                        return actions.join('');
                    }
                }
            ],
            data:[]
        }

        var options1 = {
            showFooter: true,
            striped : true, //是否显示行间隔色
            pagination : true,//是否分页
            sidePagination : 'client',//server:服务器端分页|client：前端分页
            columns: [
                {
                    field: 'Number',
                    title: '#',
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },
                {
                    field: 'id',
                    title: 'Id',
                    visible: false
                },
                {
                    field: 'roomId',
                    title: '考场编号'
                },
                {
                    field: 'location',
                    title: '考场位置'
                },
                {
                    field: 'numbers',
                    title: '容纳人数',
                    align: 'center',
                    valign: 'middle',
                    footerFormatter:function (value) {
                        var count = 0;
                        for (var i in value) {
                            count += value[i].numbers;
                        }
                        return '总人数:'+  count;
                    }
                },
                {
                    field: 'orderNum',
                    title: '排序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" onclick="printRoom('+row.id+')"><i class="fa fa-print"></i>打印</a> ');
                        return actions.join('');
                    }
                }
            ],
            data:[]
        }

        $(function () {
            $("#bootstrap-table2").bootstrapTable(optionsw);
        })

        function initChildTable(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable(options1);
            var id = row.id;
            var data = {scheduleId:id};
            $.ajax({
                type: "get",
                url:ctx+'school/examRoomClasses/getRoomList/'+id,
                async:false,
                dataType: "json",
                data:data,
                success:function (res) {
                    $(childTable).bootstrapTable("load",res);
                }
            });
        }
        
        function queryScheduleList() {
            var data = $('#formId2').serializeJSON();
            $.ajax({
                type: "post",
                url:ctx+'school/examSchedule/getScheduleList2',
                async:false,
                dataType: "json",
                data:data,
                success:function (res) {
                    $("#bootstrap-table2").bootstrapTable("load",res);
                }
            });

            // $("#bootstrap-table2").bootstrapTable('refresh', {url : ctx+'school/examSchedule/list'});
        }

        function printSchedule(scheduleId) {
            window.open(ctx + "school/examSchedule/print/"+scheduleId,"打印考场安排");
        }

        function printRoom(roomId) {
            window.open(ctx + "school/examRoomClasses/print/"+roomId,"打印考场安排");
        }


    </script>
</body>
</html>